// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   TrainAction.java

package com.iphaeton.lms.action.organize;

import com.iphaeton.common.helper.Pagination;
import com.iphaeton.common.helper.UserSession;
import com.iphaeton.exception.BusinessException;
import com.iphaeton.lms.business.organize.*;
import com.iphaeton.lms.pojo.course.Course;
import com.iphaeton.lms.pojo.organize.*;
import java.io.IOException;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import org.apache.log4j.Logger;
import org.apache.struts.action.*;

// Referenced classes of package com.iphaeton.lms.action.organize:
//            TrainBizSupportAction

public class TrainAction extends TrainBizSupportAction
{

    public TrainAction()
    {
    }

    public ActionForward setTrain(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        List list = null;
        try
        {
            UserSession userSession = (UserSession)request.getSession().getAttribute("userSession");
            String orgId = userSession.getManageOrgId();
            list = organize.findAllChildOrganize(organize.findOrganizeById(orgId));
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        request.setAttribute("list", list);
        return mapping.findForward("train_create");
    }

    public ActionForward createTrain(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String map = "";
        daf = (DynaActionForm)form;
        String name = (String)daf.get("name");
        String comment = (String)daf.get("comment");
        String teacher = (String)daf.get("teacher");
        String start_date = (String)daf.get("startDate");
        String end_date = (String)daf.get("endDate");
        String sort = (String)daf.get("sort");
        String type = (String)daf.get("type");
        String join_access = (String)daf.get("joinAccess");
        String organizeId = (String)daf.get("organizeId");
        Train t = new Train();
        t.setName(name);
        t.setComment(comment);
        t.setEndDate(end_date);
        t.setStartDate(start_date);
        t.setSort(sort);
        t.setJoinAccess(join_access);
        t.setType(type);
        t.setTeacher(teacher);
        t.setOrganizeId(organizeId);
        t.setDeleted(new Integer(1));
        try
        {
            UserSession userSession = (UserSession)request.getSession().getAttribute("userSession");
            String creater = userSession.getUserId();
            t.setCreater(creater);
            t = train.persistent(t);
            if(sort.equals("station"))
            {
                map = "train_station_assign";
                List station = organize.findGroup(null, 'g');
                request.setAttribute("station", station);
            } else
            if(sort.equals("duty"))
            {
                map = "train_duty_assign";
                List duty = organize.findGroup(null, 'z');
                request.setAttribute("duty", duty);
            } else
            if(sort.equals("group"))
            {
                map = "train_group_assign";
                List group = organize.findGroup(organize.findOrganizeById(t.getOrganizeId()), 'u');
                request.setAttribute("group", group);
            } else
            {
                map = "train_course_assign";
            }
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        request.setAttribute("train", t);
        return mapping.findForward(map);
    }

    public ActionForward selectTrain(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        int currentPage = 0;
        int pageSize = 10;
        String page = request.getParameter("page");
        String row = request.getParameter("row");
        String strState = request.getParameter("state");
        int state = Integer.parseInt(strState);
        if(row == null)
            row = "";
        List list = null;
        try
        {
            UserSession userSession = (UserSession)request.getSession().getAttribute("userSession");
            String userId = userSession.getUserId();
            if(page == null || "".equals(page))
                currentPage = 1;
            else
                currentPage = Integer.parseInt(page);
            pageInfo = train.selectTrain(userId, row, "", state, pageSize);
            pageInfo.setPage(currentPage);
            pageInfo.setRow(row);
            request.getSession().setAttribute("pageInfo", pageInfo);
            list = train.findPageList(pageInfo);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        request.setAttribute("state", strState);
        request.setAttribute("list", list);
        return mapping.findForward("train_list");
    }

    public ActionForward assignCourse(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String courseList = request.getParameter("courseList");
        String trainId = request.getParameter("trainId");
        String courseId[] = courseList.split("&");
        Train t = null;
        String map = "";
        try
        {
            t = train.findTrainById(trainId);
            for(int i = 0; i < courseId.length; i++)
                train.assignCourse(trainId, courseId[i]);

            if(t.getJoinAccess().equals("force"))
            {
                List userList = new LinkedList();
                if(t.getSort().equals("normal"))
                {
                    userList = organize.findAllUser(organize.findOrganizeById(t.getOrganizeId()), 'a');
                    request.setAttribute("user", userList);
                    map = "train_student_assign";
                } else
                if(t.getSort().equals("station") || t.getSort().equals("duty") || t.getSort().equals("group"))
                {
                    for(Iterator it = t.getGroup().iterator(); it.hasNext();)
                    {
                        userList = group.findUser(t.getOrganizeId(), ((Group)it.next()).getId());
                        for(int i = 0; i < userList.size(); i++)
                            train.assignStudent(trainId, ((User)userList.get(i)).getId(), 1);

                    }

                    map = "train_create_ok";
                }
            } else
            if(t.getJoinAccess().equals("apply"))
                map = "train_create_ok";
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("train", t);
        return mapping.findForward(map);
    }

    public ActionForward assignGroup(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String trainId = request.getParameter("trainId");
        String groupList = request.getParameter("groupList");
        String groupId[] = groupList.split("&");
        Set groupSet = new HashSet();
        Train t = null;
        try
        {
            t = train.findTrainById(trainId);
            for(int i = 0; i < groupId.length; i++)
                groupSet.add(group.findGroupById(groupId[i]));

            t.setGroup(groupSet);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("train", t);
        return mapping.findForward("train_course_assign");
    }

    public ActionForward assignStudents(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String trainId = request.getParameter("trainId");
        String userList = request.getParameter("userList");
        String id[] = userList.split("&");
        Train t = null;
        try
        {
            t = train.findTrainById(trainId);
            for(int i = 0; i < id.length; i++)
                train.assignStudent(t.getId(), id[i], 1);

        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("train", t);
        return mapping.findForward("train_create_ok");
    }

    public ActionForward getTrainDetail(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String state = request.getParameter("state");
        String map = request.getParameter("map");
        String trainId = request.getParameter("trainId");
        Train t = null;
        try
        {
            t = train.findTrainById(trainId);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("train", t);
        request.setAttribute("state", state);
        request.setAttribute("map", map);
        return mapping.findForward("train_detail");
    }

    public ActionForward getTrainStudents(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        int currentPage = 0;
        int pageSize = 10;
        String strPage = request.getParameter("page");
        String row = request.getParameter("row");
        String strState = request.getParameter("state");
        int state = Integer.parseInt(strState);
        String trainId = request.getParameter("trainId");
        List list = null;
        Train t = null;
        try
        {
            if(strPage == null || strPage.trim().equals(""))
                currentPage = 1;
            else
                currentPage = Integer.parseInt(strPage);
            pageInfo = train.getTrainStudents(trainId, state, pageSize);
            pageInfo.setPage(currentPage);
            pageInfo.setRow(row);
            request.getSession().setAttribute("pageInfo", pageInfo);
            list = train.getTrainStudents(trainId, row, state, pageSize, currentPage);
            t = train.findTrainById(trainId);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("train", t);
        request.setAttribute("list", list);
        return mapping.findForward("train_students_list");
    }

    public ActionForward getTrainCourses(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        int currentPage = 0;
        int pageSize = 10;
        String strPage = request.getParameter("page");
        String row = request.getParameter("row");
        String trainId = request.getParameter("trainId");
        List list = null;
        Train t = null;
        try
        {
            if(strPage == null || strPage.trim().equals(""))
                currentPage = 1;
            else
                currentPage = Integer.parseInt(strPage);
            pageInfo = train.getTrainCourses(trainId, pageSize);
            pageInfo.setPage(currentPage);
            pageInfo.setRow(row);
            request.getSession().setAttribute("pageInfo", pageInfo);
            list = train.getTrainCourses(trainId, row, pageSize, currentPage);
            t = train.findTrainById(trainId);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("train", t);
        request.setAttribute("list", list);
        return mapping.findForward("train_course_list");
    }

    public ActionForward removeTrain(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String map = request.getParameter("map");
        String id = request.getParameter("id");
        String strState = request.getParameter("state");
        int state = Integer.parseInt(strState);
        int currentPage = 0;
        int pageSize = 10;
        String page = request.getParameter("page");
        String trainId[] = id.split(";");
        List list = null;
        try
        {
            UserSession userSession = (UserSession)request.getSession().getAttribute("userSession");
            String userId = userSession.getUserId();
            for(int i = 0; i < trainId.length; i++)
                train.removeTrain(trainId[i]);

            if(page == null || "".equals(page))
                currentPage = 1;
            else
                currentPage = Integer.parseInt(page);
            pageInfo = train.selectTrain(userId, "", "", state, pageSize);
            pageInfo.setPage(currentPage);
            request.getSession().setAttribute("pageInfo", pageInfo);
            list = train.findPageList(pageInfo);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        request.setAttribute("state", strState);
        request.setAttribute("list", list);
        return mapping.findForward(map);
    }

    public ActionForward getConfirmTrains(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        int currentPage = 0;
        int pageSize = 10;
        String page = request.getParameter("page");
        String row = request.getParameter("row");
        if(row == null)
            row = "";
        List list = null;
        try
        {
            UserSession userSession = (UserSession)request.getSession().getAttribute("userSession");
            String userId = userSession.getUserId();
            if(page == null || "".equals(page))
                currentPage = 1;
            else
                currentPage = Integer.parseInt(page);
            pageInfo = train.selectTrain(userId, row, "apply", 1, pageSize);
            pageInfo.setPage(currentPage);
            pageInfo.setRow(row);
            request.getSession().setAttribute("pageInfo", pageInfo);
            list = train.findPageList(pageInfo);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        request.setAttribute("list", list);
        return mapping.findForward("confirm_students");
    }

    public ActionForward getApplyStudents(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String trainId = request.getParameter("trainId");
        String row = request.getParameter("row");
        String strState = request.getParameter("state");
        int state = Integer.parseInt(strState);
        int currentPage = 0;
        int pageSize = 10;
        String strPage = request.getParameter("page");
        List list = null;
        Train t = null;
        try
        {
            if(strPage == null || strPage.trim().equals(""))
                currentPage = 1;
            else
                currentPage = Integer.parseInt(strPage);
            pageInfo = train.getTrainStudents(trainId, state, pageSize);
            pageInfo.setPage(currentPage);
            pageInfo.setRow(row);
            request.getSession().setAttribute("pageInfo", pageInfo);
            list = train.getTrainStudents(trainId, row, state, pageSize, currentPage);
            t = train.findTrainById(trainId);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("train", t);
        request.setAttribute("list", list);
        request.setAttribute("state", strState);
        return mapping.findForward("train_apply_students");
    }

    public ActionForward confirmStudents(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String id = request.getParameter("id");
        String stu_id[] = id.split(";");
        String trainId = request.getParameter("trainId");
        int currentPage = 0;
        int pageSize = 10;
        String strPage = request.getParameter("page");
        String strState = request.getParameter("state");
        int state = Integer.parseInt(strState);
        List list = null;
        Train t = null;
        try
        {
            for(int i = 0; i < stu_id.length; i++)
                train.confirmStudent(trainId, stu_id[i]);

            if(strPage == null || strPage.trim().equals(""))
                currentPage = 1;
            else
                currentPage = Integer.parseInt(strPage);
            pageInfo = train.getTrainStudents(trainId, state, pageSize);
            pageInfo.setPage(currentPage);
            request.getSession().setAttribute("pageInfo", pageInfo);
            list = train.getTrainStudents(trainId, "", state, pageSize, currentPage);
            t = train.findTrainById(trainId);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("train", t);
        request.setAttribute("list", list);
        request.setAttribute("state", strState);
        return mapping.findForward("train_apply_students");
    }

    public ActionForward refuseStudents(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String id = request.getParameter("id");
        String stu_id[] = id.split(";");
        String trainId = request.getParameter("trainId");
        int currentPage = 0;
        int pageSize = 10;
        String strPage = request.getParameter("page");
        String strState = request.getParameter("state");
        int state = Integer.parseInt(strState);
        List list = null;
        Train t = null;
        try
        {
            for(int i = 0; i < stu_id.length; i++)
                train.removeStudent(stu_id[i], trainId);

            if(strPage == null || strPage.trim().equals(""))
                currentPage = 1;
            else
                currentPage = Integer.parseInt(strPage);
            pageInfo = train.getTrainStudents(trainId, state, pageSize);
            pageInfo.setPage(currentPage);
            request.getSession().setAttribute("pageInfo", pageInfo);
            list = train.getTrainStudents(trainId, "", state, pageSize, currentPage);
            t = train.findTrainById(trainId);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("train", t);
        request.setAttribute("list", list);
        request.setAttribute("state", strState);
        return mapping.findForward("train_apply_students");
    }

    public ActionForward trainUserEdit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String type = request.getParameter("type");
        String trainId = request.getParameter("trainId");
        Train t = null;
        String map = "";
        try
        {
            t = train.findTrainById(trainId);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        if(type.equals("organize"))
            map = "organize_user_choice";
        else
        if(type.equals("u") || type.equals("g") || type.equals("z"))
            map = "group_user_choice";
        request.setAttribute("train", t);
        return mapping.findForward(map);
    }

    public ActionForward trainUserUpdate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        int currentPage = 0;
        int pageSize = 10;
        String strPage = request.getParameter("page");
        String userList = request.getParameter("userList");
        String trainId = request.getParameter("trainId");
        String id[] = userList.split("&");
        Set userSet = null;
        Train t = null;
        List list = null;
        try
        {
            t = train.findTrainById(trainId);
            userSet = t.getUser();
            for(Iterator it = userSet.iterator(); it.hasNext(); train.removeStudent(((User)it.next()).getId(), trainId));
            for(int i = 0; i < id.length; i++)
                train.assignStudent(trainId, id[i], 1);

            if(strPage == null || strPage.trim().equals(""))
                currentPage = 1;
            else
                currentPage = Integer.parseInt(strPage);
            pageInfo = train.getTrainStudents(trainId, 1, pageSize);
            pageInfo.setPage(currentPage);
            request.getSession().setAttribute("pageInfo", pageInfo);
            list = train.getTrainStudents(trainId, "", 1, pageSize, currentPage);
            t = train.findTrainById(trainId);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("train", t);
        request.setAttribute("list", list);
        return mapping.findForward("train_students_list");
    }

    public ActionForward trainCourseEdit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String trainId = request.getParameter("trainId");
        Train t = null;
        try
        {
            t = train.findTrainById(trainId);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("train", t);
        return mapping.findForward("train_course_edit");
    }

    public ActionForward trainCourseUpdate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        int currentPage = 0;
        int pageSize = 10;
        String strPage = request.getParameter("page");
        String row = request.getParameter("row");
        String courseList = request.getParameter("courseList");
        String trainId = request.getParameter("trainId");
        String id[] = courseList.split("&");
        Set courseSet = null;
        Train t = null;
        List list = null;
        try
        {
            t = train.findTrainById(trainId);
            courseSet = t.getCourse();
            for(Iterator it = courseSet.iterator(); it.hasNext(); train.removeCourse(((Course)it.next()).getId(), trainId));
            for(int i = 0; i < id.length; i++)
                train.assignCourse(trainId, id[i]);

            if(strPage == null || strPage.trim().equals(""))
                currentPage = 1;
            else
                currentPage = Integer.parseInt(strPage);
            pageInfo = train.getTrainCourses(trainId, pageSize);
            pageInfo.setPage(currentPage);
            pageInfo.setRow(row);
            request.getSession().setAttribute("pageInfo", pageInfo);
            list = train.getTrainCourses(trainId, row, pageSize, currentPage);
            t = train.findTrainById(trainId);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("train", t);
        request.setAttribute("list", list);
        return mapping.findForward("train_course_list");
    }

    public ActionForward currentTrain(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String strState = request.getParameter("state");
        int state = 0;
        if(strState != null)
            state = Integer.parseInt(strState);
        String row = request.getParameter("row");
        List list = null;
        try
        {
            UserSession userSession = (UserSession)request.getSession().getAttribute("userSession");
            String uid = userSession.getId();
            list = train.currentTrain(user.findUserById(uid), row, state);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        request.setAttribute("list", list);
        request.setAttribute("state", strState);
        return mapping.findForward("current_train");
    }

    public ActionForward applyTrain(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String train_id = request.getParameter("id");
        try
        {
            UserSession userSession = (UserSession)request.getSession().getAttribute("userSession");
            String user_id = userSession.getId();
            train.assignStudent(train_id, user_id, 2);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        return mapping.findForward("currentTrain");
    }

    public ActionForward removeTrainApply(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String train_id = request.getParameter("id");
        try
        {
            UserSession userSession = (UserSession)request.getSession().getAttribute("userSession");
            String user_id = userSession.getId();
            train.removeStudent(user_id, train_id);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        return mapping.findForward("applyedTrain");
    }

    public ActionForward myTrain(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String strState = request.getParameter("state");
        String row = request.getParameter("row");
        int state = Integer.parseInt(strState);
        List list = null;
        try
        {
            UserSession userSession = (UserSession)request.getSession().getAttribute("userSession");
            String user_id = userSession.getId();
            list = train.myTrain(user_id, row, state);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            ne.printStackTrace();
            return mapping.findForward("session_dead");
        }
        request.setAttribute("list", list);
        request.setAttribute("state", strState);
        return mapping.findForward("my_train");
    }

    public ActionForward trainManage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        int currentPage = 0;
        int pageSize = 10;
        String page = request.getParameter("page");
        String row = request.getParameter("row");
        if(row == null)
            row = "";
        List list = null;
        try
        {
            UserSession userSession = (UserSession)request.getSession().getAttribute("userSession");
            String userId = userSession.getUserId();
            String orgId = userSession.getManageOrgId();
            if(page == null || "".equals(page))
                currentPage = 1;
            else
                currentPage = Integer.parseInt(page);
            pageInfo = train.myManageTrain(userId, organize.findOrganizeById(orgId).getUrl(), row, pageSize);
            pageInfo.setPage(currentPage);
            pageInfo.setRow(row);
            request.getSession().setAttribute("pageInfo", pageInfo);
            list = train.findPageList(pageInfo);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        request.setAttribute("list", list);
        return mapping.findForward("train_manage");
    }

    public ActionForward trainReport(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String course_id = request.getParameter("cid");
        String user_id = request.getParameter("uid");
        String row = request.getParameter("row");
        String id = request.getParameter("id");
        List list;
        try
        {
            list = train.getTrainReport(id, course_id, user_id, row);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("list", list);
        return mapping.findForward("train_report");
    }

    public ActionForward removeTrainStudent(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String trainId = request.getParameter("trainId");
        String userId = request.getParameter("userId");
        int currentPage = 1;
        int pageSize = 10;
        List list = null;
        Train t = null;
        try
        {
            train.removeStudent(userId, trainId);
            pageInfo = train.getTrainStudents(trainId, 1, pageSize);
            pageInfo.setPage(currentPage);
            request.getSession().setAttribute("pageInfo", pageInfo);
            list = train.getTrainStudents(trainId, "", 1, pageSize, currentPage);
            t = train.findTrainById(trainId);
        }
        catch(BusinessException e)
        {
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("train", t);
        request.setAttribute("list", list);
        return mapping.findForward("train_students_list");
    }

    public ActionForward removeTrainCourse(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String trainId = request.getParameter("trainId");
        String courseId = request.getParameter("courseId");
        String strPage = request.getParameter("page");
        String row = request.getParameter("row");
        int currentPage = 1;
        int pageSize = 10;
        List list = null;
        Train t = null;
        try
        {
            train.removeCourse(courseId, trainId);
            if(strPage != null && !strPage.trim().equals(""))
                currentPage = Integer.parseInt(strPage);
            pageInfo = train.getTrainCourses(trainId, pageSize);
            pageInfo.setPage(currentPage);
            pageInfo.setRow(row);
            request.getSession().setAttribute("pageInfo", pageInfo);
            list = train.getTrainCourses(trainId, row, pageSize, currentPage);
            t = train.findTrainById(trainId);
        }
        catch(BusinessException e)
        {
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("train", t);
        request.setAttribute("list", list);
        return mapping.findForward("train_course_list");
    }

    public ActionForward trainStart(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String train_id = request.getParameter("id");
        List list = null;
        Train t = null;
        try
        {
            String user_id = ((UserSession)request.getSession().getAttribute("userSession")).getId();
            t = train.findTrainById(train_id);
            list = train.getTrainUserCourse(user_id, train_id);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        request.setAttribute("list", list);
        request.setAttribute("train", t);
        return mapping.findForward("train_start");
    }

    public ActionForward trainCourseInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String train_id = request.getParameter("id");
        List list = null;
        Train t = null;
        try
        {
            String user_id = ((UserSession)request.getSession().getAttribute("userSession")).getId();
            t = train.findTrainById(train_id);
            list = train.getTrainUserCourse(user_id, train_id);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        request.setAttribute("list", list);
        request.setAttribute("train", t);
        return mapping.findForward("my_train_info");
    }

    private static Logger logger;
    private DynaActionForm daf;
    private Pagination pageInfo;
    static Class class$0; /* synthetic field */

    static 
    {
        logger = Logger.getLogger(com.iphaeton.lms.action.organize.TrainAction.class.getName());
    }
}
